﻿using AutoMapper;
using MediatR;
using SheepStorage.API.Application.Command.SheepMomDeliveryCommand;
using SheepStorage.API.Application.Command.SheepMomPergnantCommand;
using SheepStorage.API.Baseclass;
using SheepStorage.Domain.Entity;
using SheepStorage.Service.DataImp;
using SheepStorage.Service.Interface;

namespace SheepStorage.API.Application.CommandHandlers.SheepMomDeliveryHandler
{
    public class SheepMomDeliveryAddCommandHandler : IRequestHandler<SheepMomDeliveryAddCommand, Results<int>>
    {
        private readonly ISheepMomDeliveryService SheepMomDeliveryService;
        private readonly IMapper _mapper;
        public SheepMomDeliveryAddCommandHandler(ISheepMomDeliveryService SheepMomDeliveryService, IMapper mapper)
        {
            this.SheepMomDeliveryService = SheepMomDeliveryService;
            _mapper = mapper;
        }

        public async Task<Results<int>> Handle(SheepMomDeliveryAddCommand request, CancellationToken cancellationToken)
        {
            var result = _mapper.Map<List<SheepMomDelivery>>(request.DeliveryList);

            return Results<int>.DataResult(await SheepMomDeliveryService.AddSheepMomDelivery(result));
        }
    }
}
